//
//  TypeCellAdapter.swift
//  Bee
//
//  Created by kyson on 15/12/31.
//  Copyright © 2015年 kyson. All rights reserved.
//

import UIKit

class TypeCellAdapter: NSObject ,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate {
    
    private var selectedCellNum:NSNumber = 0

    var titles:NSArray = ["明信片","海报","字体"]
    
    @available(iOS 6.0, *)
    internal func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
        return 3
    }
    
    // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
    @available(iOS 6.0, *)
    internal func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
        let cell  = collectionView.dequeueReusableCellWithReuseIdentifier("type", forIndexPath: indexPath) as! TypeCell
        
        cell.cellTitle = titles[indexPath.row] as! String
        
        //设置是否选中
        if(indexPath.row == self.selectedCellNum.integerValue){
            cell.isButtonSelected = true
        }else{
            cell.isButtonSelected = false
        }
        
        cell.cellClickCallBack = {
            self.selectedCellNum = NSNumber.init(integer: indexPath.row)
            //先设置所有的cell都是未选中状态
            for index in 0...(self.titles.count-1){
                let tempIndexPath = NSIndexPath.init(forItem: index, inSection: 0)
                let tempCell = collectionView .cellForItemAtIndexPath(tempIndexPath) as! TypeCell
                tempCell.isButtonSelected = false
            }
            
            cell.isButtonSelected = true
        }
        
        
        
        return cell
    }
    
    
    //    internal func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize{
    //        return CGSizeMake(UIScreen.mainScreen().bounds.width, 8)
    //    }
    
    internal func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{
        var size:CGSize!
        switch(indexPath.section){
        case 0:
            size = CGSizeMake(UIScreen.mainScreen().bounds.width / 3, 35)
            break
            //        case 1:
            //            size = CGSizeMake(50, 40)
            //            break
            //        case 2:
            //            size = CGSizeMake(60, 30)
            //            break
        default:
            break
        }
        return size
    }
    
    
    //    internal func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat{
    //        return 2
    //    }
    //
    //
    //    internal func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets{
    //        return UIEdgeInsetsMake(0, 0, 0, 0)
    //    }
    //    
    internal func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int{
        return 1
    }
    
}
